/*
 * @Author: nns4
 * @Date: 2019-11-20 13:51:17
 * @LastEditors: nns4
 * @LastEditTime: 2019-12-03 14:55:35
 * @FilePath: /wxShop/src/libs/filter.js
 * @Description: 公共过滤器
 */
import Vue from 'vue'
const filters = {
  /**
   * @description:  对钱数的处理
   * @param {x:价格,n 保留几位小数 } 
   * @return:  返回  价格.几位小数
   */
  money: (x, n = 2) => {
    var f = parseFloat(x);
    if (isNaN(f)) {
      return 0.00
    }
    var f = Math.round(x * 100) / 100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
      rs = s.length;
      s += '.';
    }
    while (s.length <= rs + n) {
      s += '0';
    }
    return s;
  }
}

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
});